<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar title="我的认养" title-size="36" title-color="#333"></u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#10A28F"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item class="swiperItem" v-for="(item2, index) in tabsList" :key="index">
          <z-paging
            ref="paging"
            v-model="itemList[index]"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList[index]" :key="index1">
                <view
                  @click="onOrderDetail(item)"
                  class="order-top dis-flex flex-y-center flex-y-between"
                >
                  <view
                    class="dis-flex flex-y-center u-line-1"
                    style="flex: 1; margin-right: 48rpx"
                  >
                    <u-avatar size="50"></u-avatar>
                    <view class="shop-name">农场名称农场名称农场名称</view>
                  </view>
                  <view class="order-stat" v-if="index1 == 0"> 种植中 </view>
                  <view class="order-stat" v-if="index1 == 1"> 养殖中 </view>
                </view>
                <u-line></u-line>
                <view class="order-goods" @click="onOrderDetail(item)">
                  <u-image
                    class=""
                    :name="item.picUrl"
                    width="178rpx"
                    height="178rpx"
                    border-radius="10"
                  ></u-image>
                  <view class="orde-riget">
                    <view class="goods-title"> 园区2号地大白菜认领 </view>
                    <view class="goods-speci"> 大白菜 2㎡ </view>
                    <view class="dis-flex flex-y-center flex-y-between" style="margin-top: 10px">
                      <view class="goods-price">¥150</view>
                      <text class="goods-num">（已付定金：¥80）</text>
                    </view>
                  </view>
                </view>
                <u-line></u-line>

                <view class="btn-group" v-if="index1 == 0">
                  <text style="flex: 1">预计采摘时间：2024-12-10</text>
                  <view class="solid-btn btn" @click="show = true"> 立即支付 </view>
                </view>
                <view class="btn-group" v-else @click="onOrderDetail(item)">
                  <text style="flex: 1">预计采摘时间：2024-12-10</text>
                  <view class="hollow-btn btn"> 联系牧场主 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>
    <u-popup v-model="show" height="auto" border-radius="15" mode="bottom">
      <view class="share-box">
        <view class="" style="font-size: 30rpx; text-align: center; padding: 50rpx; color: #666666">
          还差一人，去邀请你好友吧
        </view>
        <view class="group dis-flex flex-y-around">
          <view class="group-item">
            <u-icon name="/static/wxhy.png" size="96"></u-icon>
            <view>微信好友</view>
          </view>
          <view class="group-item">
            <u-icon name="/static/pyq.png" size="96"></u-icon>
            <view>微信好友</view>
          </view>
        </view>
        <u-gap height="20" bg-color="#F0F1F2" />
        <view
          class=""
          @click="show = false"
          style="font-size: 30rpx; height: 100rpx; line-height: 100rpx; text-align: center"
        >
          取消
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      show: false,
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部',
          status: ''
        },
        {
          name: '种植中',
          status: 0
        },
        {
          name: '养殖中',
          status: 1
        },
        {
          name: '待支付',
          status: 2
        },
        {
          name: '待收货',
          status: 2
        },
        {
          name: '待评价',
          status: 2
        },
        {
          name: '已完成',
          status: 2
        }
      ],
      itemList: [[{}, {}, {}], [], [], []]
    }
  },
  onLoad() {
    this.queryList()
  },
  computed: {
    countdown: function () {
      return (item) => {
        let now = new Date().getTime()
        if (item > now) {
          let difference = item - now
          console.log(',,', difference)
          if (difference > 24 * 3600000) {
            return Math.floor(difference / (240 * 3600000)) + '天'
          } else if (difference > 3600000) {
            return Math.floor(difference / 3600000) + '小时'
          } else if (difference > 6000) {
            return Math.floor(difference / 6000) + '分'
          }
          return '即将超时'
        }
      }
    }
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      if (this.itemList[this.scurrent].length == 0) {
        this.queryList()
      }
    },

    queryList(page = 1, pageSize = 10) {
      // this.$u.get("/app-api/promotion/combination-record/page",{
      // pageNo: page,
      // pageSize,
      // status: this.tabsList[this.scurrent].status
      // }).then(res=>{
      // 	this.$refs.paging[this.scurrent].complete(res.data.list);
      // });
    },

    onOrderDetail(item) {
      this.$utils.route({
        url: '/goods/group-order-details/group-order-details',
        params: {
          id: item.id,
          orderId: item.orderId
        }
      })
    },
    onShare() {}
  }
}
</script>

<style lang="scss">
page {
  background: #eeeeef;
}
.share-box {
  .group {
    margin: 20rpx;
    .group-item {
      text-align: center;
      font-size: 24rpx;
      color: #333333;
      line-height: 44rpx;
    }
  }
}
.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  margin-bottom: 20rpx;
  border-radius: 6px;
  padding: 20rpx;
}

.orderView {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding-top: 20rpx;
  padding-bottom: 20rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
  border-bottom: 1px solid rgba(193, 192, 201, 0.3);
}

/*   hh */
.order-top {
  position: relative;
  padding: 15rpx 0;
}

.order-top-tip {
  color: #999999;
}

.order-goods {
  display: flex;
  margin: 20rpx 0;
}

.goods-img {
  border-radius: 20rpx;
}

.orde-riget {
  margin-left: 20rpx;
  /* line-height: 55rpx; */
  font-size: 30rpx;
}

.goods-speci {
  position: relative;
  font-size: 26rpx;
  color: #666666;
  margin-top: 20rpx;
}

.goods-num {
  color: #999999;
  font-size: 26rpx;
}
.goods-price {
  font-size: 32rpx;
  color: #fa453c;
  font-weight: 600;
}
.bold {
  font-size: 36rpx;
  font-weight: 600;
}
.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 30rpx;
  margin: 20rpx 0;
}

.btn-group {
  display: flex;
  align-items: center;
  font-size: 26rpx;
  color: #666666;
}

.btn {
  display: inline-block;
  padding: 15rpx 20rpx;
  border-radius: 35rpx;
  font-size: 24rpx;
  margin-left: 15rpx;
}
.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}
.solid-btn {
  background-color: #10a28f;
  color: #fff;
}

/* xxx */
.orderNum {
  flex: 1;
  font-size: 28rpx;
  font-weight: 400;
  color: #333333;
}

.orderStatus {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 24rpx;
  font-weight: 400;
  color: #333333;
}

.orderStatus text {
  font-size: 28rpx;
  font-weight: 500;
  color: #22b857;
}

.orderNext {
  width: 14rpx;
  margin-left: 10rpx;
}

.reasonView {
  font-size: 28rpx;
  font-weight: 500;
  color: #f6632d;
  padding: 20rpx;
  padding-bottom: 0rpx;
}

.goodsView {
  display: flex;
  flex-direction: row;
  margin-left: 30rpx;
  margin-right: 30rpx;
  padding-top: 20rpx;
  padding-bottom: 20rpx;
  border-bottom: 1px solid rgba(193, 192, 201, 0.2);
}

.goodsData {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-left: 20rpx;
}

.goodsName {
  display: flex;
  flex-direction: row;
}

.goodsTitle {
  font-size: 28rpx;
  font-weight: 400;
  color: #333333;
}

.skuView {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-top: 10rpx;
}

.goodsSku {
  flex: 1;
  font-size: 24rpx;
  color: #999;
}

.goodsPrice {
  font-size: 30rpx;
  color: #333;
  margin-top: 10rpx;
}

.goodsNum {
  font-size: 26rpx;
  font-weight: 400;
  color: #787878;
}

.totalView {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-top: 20rpx;
  padding-bottom: 20rpx;
  margin-right: 30rpx;
  margin-left: 30rpx;
}

.priceView {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 26rpx;
  font-weight: 400;
  color: #333;
}

.allPrice {
  font-size: 30rpx;
  font-weight: bold;
  color: #f23521;
}

.orderBtn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  margin-left: 30rpx;
  margin-right: 30rpx;
}

.codeView {
  flex: 1;
  font-size: 36rpx;
  font-weight: 500;
  color: #333333;
  margin-top: 10rpx;
  margin-bottom: 30rpx;
}

.confrimOrder {
  font-size: 26rpx;
  color: #ffffff;
  background: #22b857;
  border-radius: 35rpx;
  width: 150rpx;
  height: 50rpx;
  line-height: 50rpx;
  text-align: center;
  margin-left: 30rpx;
  margin-top: 10rpx;
  margin-bottom: 30rpx;
}
.order-stat {
  font-size: 26rpx;
  color: #333333;
}
.shop-name {
  font-size: 30rpx;
  margin-left: 10rpx;
}
</style>
